package fr.imag.ufrima.ctte.gui.views;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.List;

import javax.swing.JPanel;
import javax.swing.event.ListDataListener;

import fr.imag.ufrima.ctte.ImagCTTE;
import fr.imag.ufrima.ctte.Operator;

public class OperatorPropertiesSubView extends SubView {	
	private Operator operator;
	/**
	 * Constructor
	 */
	public OperatorPropertiesSubView(ImagCTTE imagCTTE){
		super(imagCTTE, "Operator Properties");
		InitComponents();
		setOperator(imagCTTE.getCurrentTaskDiagram().getSelectedOperator());
		cmbOperatorType.addActionListener(new ActionListener(){			
			public void actionPerformed(ActionEvent arg0) {
				String type = (String)cmbOperatorType.getSelectedItem();
				operator.setType(type);				
			}
		});
	}
	public void setOperator(Operator operator){
		this.operator = operator;
		
		// initialize list
		List<String> types = operator.getOperatorTypes();
		Iterator it1 = types.iterator();
		while (it1.hasNext()){
			cmbOperatorType.addItem(it1.next());			
		}
		cmbOperatorType.setSelectedItem(operator.getTypeAsString());
	}
	/**
	 * Initialize componenets
	 */
	protected void InitComponents(){

        lblOperatorType = new javax.swing.JLabel();
        cmbOperatorType = new javax.swing.JComboBox();

        lblOperatorType.setText("Operator Type:");

        //cmbOperatorType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblOperatorType)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cmbOperatorType, 0, 144, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblOperatorType)
                    .addComponent(cmbOperatorType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(169, Short.MAX_VALUE))
        );
	}
	/**
	 * Components
	 */
	private javax.swing.JComboBox cmbOperatorType;
    private javax.swing.JLabel lblOperatorType;
}
